import { createStore, applyMiddleware } from 'redux'
import { combineReducers } from 'redux-immutable'
import thunk from 'redux-thunk'
import { composeWithDevTools } from 'redux-devtools-extension'

// 自动化引入 
let moduleFn = require.context('./reducers', false, /\.js$/)
let modules = moduleFn.keys().reduce((p, c) => {
  let mod = moduleFn(c).default;
  let modName = c.match(/\.\/(\w+)\.js$/)[1]
  p[modName] = mod
  return p
}, {})
// 合并多个reducer
let reducer = combineReducers(modules)

export default createStore(
  reducer,
  composeWithDevTools(applyMiddleware(thunk))
)



